package com.bjpowernode.service.impl;

import com.bjpowernode.constant.Constant;
import com.bjpowernode.entity.TActivity;
import com.bjpowernode.mapper.TActivityMapper;
import com.bjpowernode.query.ActivityQuery;
import com.bjpowernode.query.BaseQuery;
import com.bjpowernode.service.ActivityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ActivityServiceImpl implements ActivityService {

    private final TActivityMapper tActivityMapper;

    @Override
    public PageInfo<TActivity> getActivityByPage(Integer current, ActivityQuery activityQuery) {
        //设置页码和每页显示的数据量
        PageHelper.startPage(current, Constant.PAGE_SIZE);

        //查询数据库
        List<TActivity> tActivityList = tActivityMapper.selectByPage(new BaseQuery(),activityQuery);

        //构建分页对象
        PageInfo<TActivity> pageInfo = new PageInfo<>(tActivityList);
        return pageInfo;
    }

    @Override
    public TActivity selectById(Integer id) {
        return tActivityMapper.selectById(id);
    }
}
